<?php

namespace models;

/**
 * @Entity
 * @Table(name="account")
 */
 
class Account {
	/**
	 * @Id
	 * @Column(type="integer")
	 */
	protected $id = null;
	
	public function getId() { return $this->id; }
	
	/**
	 * @Column(name="balance", type="decimal")
	 */
	protected $balance;
	
	public function getBalance() {
		return $this->balance;
	}
	
	/**
	 * @Column(name="active", type="boolean")
	 */
	protected $active;
	
	public function getActive() {
		return $this->active;
	}
	
	/**
	 * @Column(name="type", type="string")
	 */
	protected $type;
	
	public function getType() {
		return $this->type;
	}
	
	/**
	 * @ManyToMany(targetEntity="User", mappedBy="accounts")
	 */
	protected $owners = null;
	
	public function getOwners() {
		return $this->owners;
	}
	
	public function getOwnerName($n=0) {
		if($this->owners[$n]) {
			return $this->owners[$n]->getLogin();
		} else {
			return '';
		}
	}
	
	public function getJSON() {
		return json_encode(array(
			'id'=>$this->id,
			'balance'=>$this->balance,
			'active'=>$this->active,
			'type'=>$this->type));
	}
	
	public static function getDefaultColumns() {
		$columns = new \Framework\SlickGrid\DoctrineColumnCollection('acct');
		$columns->addHiddenColumn('id', 'getId');
		$columns->addColumn('balance', 'Balance', 'getBalance', array('sortable'=>true, 'cssClass'=>'acct'));
		$columns->addColumn('active', 'Active', 'getActive', array('sortable'=>true, 'cssClass'=>'acct'));
		$columns->addColumn('type', 'Type', 'getType', array('sortable'=>true, 'cssClass'=>'acct'));
		return $columns;
	}
}
